package src.main.java.org.properties;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

/*
* 读取属性文件
* */
public class Test1 {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        //加载属性文件中的键值对数据到properties对象中去
        properties.load(new FileReader("E:\\JavaLearn\\javaCode\\src\\users.properties"));
        System.out.println(properties);
        //根据键取值
        System.out.println(properties.getProperty("zhangsan"));

        Set<String> strings = properties.stringPropertyNames();
        for (String string : strings) {
            String property = properties.getProperty(string);
            System.out.println(string+"=="+property);
        }
        properties.forEach((k,v)->{
            System.out.println(k+"--"+v);
        });
    }
}
